package com.sdry.web.controller;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.hpf.LineSideLibraryOut;
import com.sdry.model.hpf.Part;
import com.sdry.model.hpf.Product;
import com.sdry.model.jyy.Cut;
import com.sdry.model.jyy.CutExample;
import com.sdry.model.jyy.Shedudetail;
import com.sdry.model.jyy.ShedudetailExample;
import com.sdry.model.jyy.Solid;
import com.sdry.model.jyy.SolidExample;
import com.sdry.model.llm.EmployeeRecord;
import com.sdry.model.llm.ProductionLine;
import com.sdry.model.llm.Team;
import com.sdry.model.llm.TeamRecord;
import com.sdry.model.lz.DeviceModel;
import com.sdry.model.report.OutputMaterielReportDataUtils;
import com.sdry.model.report.ReportDataUtils;
import com.sdry.model.workplace.Assemble;
import com.sdry.model.workplace.Centrifugal;
import com.sdry.model.workplace.CentrifugalExample;
import com.sdry.model.workplace.CentrifugalExample.Criteria;
import com.sdry.model.workplace.MousseBundleSample;
import com.sdry.model.workplace.MousseBundleSampleExample;
import com.sdry.service.hpf.ProductService;
import com.sdry.service.jyy.CutServise;
import com.sdry.service.jyy.ShedudetailServise;
import com.sdry.service.jyy.SolidServise;
import com.sdry.service.report.OutputMaterielReportDataUtilsService;
import com.sdry.service.report.ReportDataUtilsService;
import com.sdry.service.report.ReportServise;
import com.sdry.service.workplace.CentrifugalServise;
import com.sdry.service.workplace.MousseBundleSampleServise;
import com.sdry.service.workplace.OthersService;
import com.sdry.utils.BeanReflexUtil;
import com.sdry.utils.DateCalculationUtil;
import com.sdry.utils.ResponseUtil;
import com.sdry.utils.StringUtil;

/**
 * 
 * @ClassName:JumpPageController
 * @Description:看板
 * @Author tdd
 * @Date 2018年4月25日下午5:05:43
 * @version 1.0
 */
@Controller
@RequestMapping("/report")
@Component
public class ReportController {
	@Resource ReportDataUtilsService reportDataUtilsService;
    @Resource OutputMaterielReportDataUtilsService outputMaterielReportDataUtilsService;
    @Resource CentrifugalServise centrifugalServise;
    @Resource OthersService othersService;
    @Resource MousseBundleSampleServise mousseBundleSampleServise;
    @Resource CutServise cutServise;
    @Resource SolidServise solidServise;
    @Resource ReportServise reportServise;
    @Resource ProductService productService;
    
	public static String[][] productArr = 
		{
			 {"01","PSH2-0960-T-01","热法","0960"}
			 ,{"02","PSH2-0980-T-02","热法","0980"}
			 ,{"03","PSH1-1060-B-03","湿法","1060"}
			 ,{"04","PSH1-1080-C-04","湿法","1080"}
		};
	/**
	 * 离心机现况版跳转页面
	 * @return
	 */
	@RequestMapping("/deviceReport")
	public String lxj(Model model) {
		List<String> list= new ArrayList<>();
		//list.add("膜丝");
		String ms = "膜丝";
		ProductionLine productionLine = new ProductionLine();
		List<ProductionLine> productionLines = othersService.productionLineByMution(productionLine);
		for (int i = 0; i < productionLines.size(); i++) {
			list.add(ms+productionLines.get(i).getLineName());
		}
		list.add("组装");
		//list.add("离心");
		String lx = "离心";
		DeviceModel deviceModel = new DeviceModel();
		List<DeviceModel> devices = othersService.deviceByMution(deviceModel );
		for (int i = 0; i < devices.size(); i++) {
			list.add(lx + devices.get(i).getDeviceNo());
		}
		list.add("切割");
		list.add("固化");
		model.addAttribute("devices",list);
		return "/report/device";
	}
	 
	 /**
     * 根据当前日期查询离心信息
     * @param response 响应
     * @param format 日期
     * @param deviceName 设备名称
     * @throws Exception 异常
     */
    @RequestMapping("/selectDeviceReportByMonth")
    public void selectDeviceReportByMonth(HttpServletResponse response,
							    		String format,String deviceName) throws Exception {
    	List<ReportDataUtils> list = new ArrayList<>();
    	/*Date da = new Date();
		SimpleDateFormat msdf = new SimpleDateFormat("yyyy-MM");
		String m = msdf.format(da);
		//当前月之前的
    	if(bjYearMonth(format, m)){
    		ReportDataUtils param = new ReportDataUtils();
    		param.setDate(format);
    		param.setDeviceName(deviceName);
    		list = reportDataUtilsService.queryAllByMution(param);
    	}else{
    		if (m.equals(format)) {
    			list = chaDeviceReportByMonth(format, deviceName);
			}
    	}*/
    	if(null != deviceName && !"".equals(deviceName)){
	    	if(null == format || "".equals(format)){
				Date da = new Date();
				SimpleDateFormat msdf = new SimpleDateFormat("yyyy-MM");
				format = msdf.format(da);
			}
	    	ReportDataUtils param = new ReportDataUtils();
			param.setDate(format);
			param.setDeviceName(deviceName);
	    	list = reportDataUtilsService.queryAllByMution(param);
    	}
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("total", list.size());
        jsonObject.put("rows", list);
        ResponseUtil.write(response, jsonObject);
    }
    
    
   
    /**
     * 获取组装产量报表
     * @param format 年月
     * @return 报表
     * @throws ParseException 
     */
    public List<ReportDataUtils> selectZzByMonth(String format) throws ParseException{
    	List<ReportDataUtils> list = new ArrayList<>();
    	//当月数据
    	Map<String, Object> map = new HashMap<>();
    	map.put("atube", "");
    	map.put("atime", format);
    	map.put("product", "");
    	//是否删除
    	map.put("aremark", "");
    	List<Assemble> assems = othersService.selectAtubeByDateAndProduct(map);
    	
    	List<String> monthFullDay = getMonthFullDay(format);
    	
    	
    	for (int i = 0; i < monthFullDay.size(); i++) {
    		ReportDataUtils reportData = new ReportDataUtils();
    		ReportDataUtils reportData2 = new ReportDataUtils();
    		//白班
    		reportData.setTime(monthFullDay.get(i));
    		reportData2.setTime(monthFullDay.get(i));
    		int pnum1 = 0;
    		int pnum2 = 0;
    		int pnum3 = 0;
    		int pnum4 = 0;
    		int wpnum1 = 0;
    		int wpnum2 = 0;
    		int wpnum3 = 0;
    		int wpnum4 = 0;
    		for (int j = 0; j < assems.size(); j++) {
				if("白班".equals(assems.get(j).getAremark4())){
	    			if (assems.get(j).getAtube().indexOf(productArr[0][3]) != -1) {
	    				pnum1++;
	    			}else if (assems.get(j).getAtube().indexOf(productArr[1][3]) != -1) {
	    				pnum2++;
	    			}else if (assems.get(j).getAtube().indexOf(productArr[2][3]) != -1) {
	    				pnum3++;
	    			}else if (assems.get(j).getAtube().indexOf(productArr[3][3]) != -1) {
	    				pnum4++;
	    			}
				}else if("晚班".equals(assems.get(j).getAremark4())){
					if (assems.get(j).getAtube().indexOf(productArr[0][3]) != -1) {
	    				wpnum1++;
	    			}else if (assems.get(j).getAtube().indexOf(productArr[1][3]) != -1) {
	    				wpnum2++;
	    			}else if (assems.get(j).getAtube().indexOf(productArr[2][3]) != -1) {
	    				wpnum3++;
	    			}else if (assems.get(j).getAtube().indexOf(productArr[3][3]) != -1) {
	    				wpnum4++;
	    			}
				}
			}
    		reportData.setBanci("白班");
    		reportData.setPnum1(pnum1+"");
    		reportData.setPnum2(pnum2+"");
    		reportData.setPnum3(pnum3+"");
    		reportData.setPnum4(pnum4+"");
    		reportData.setPtype1(productArr[0][3]);
    		reportData.setPtype2(productArr[1][3]);
    		reportData.setPtype3(productArr[2][3]);
    		reportData.setPtype4(productArr[3][3]);
    		list.add(reportData);
    		reportData2.setBanci("晚班");
    		reportData2.setPnum1(wpnum1+"");
    		reportData2.setPnum2(wpnum2+"");
    		reportData2.setPnum3(wpnum3+"");
    		reportData2.setPnum4(wpnum4+"");
    		reportData2.setPtype1(productArr[0][3]);
    		reportData2.setPtype2(productArr[1][3]);
    		reportData2.setPtype3(productArr[2][3]);
    		reportData2.setPtype4(productArr[3][3]);
    		list.add(reportData2);
    		reportData = null;
    		reportData2 = null;
    	}
    	return list;
    }
   
    /**
     * 获取膜丝产量报表
     * @param format 年月
     * @return 报表
     */
    public List<ReportDataUtils> selectMsByMonth(String format){
    	List<ReportDataUtils> list = new ArrayList<>();
    	List<String> monthFullDay = getMonthFullDay(format);
    	for (int i = 0; i < monthFullDay.size(); i++) {
    		ReportDataUtils reportData = new ReportDataUtils();
    		ReportDataUtils reportData2 = new ReportDataUtils();
    		
    		MousseBundleSampleExample example = new MousseBundleSampleExample();
        	com.sdry.model.workplace.MousseBundleSampleExample.Criteria createCriteria = example.createCriteria();
    		//白班
    		reportData.setTime(monthFullDay.get(i));
    		reportData2.setTime(monthFullDay.get(i));
			reportData.setBanci("白班");
    		int pnum1 = 0;
    		int pnum2 = 0;
    		int pnum3 = 0;
    		int pnum4 = 0;
    		createCriteria.andMbstimeLike("%"+monthFullDay.get(i)+"%");
    		createCriteria.andMbsremark4EqualTo("白班");
    		List<MousseBundleSample> baiList = mousseBundleSampleServise.selectByExample(example);
			for (int j = 0; j < baiList.size(); j++) {
				if (productArr[0][0].equals(baiList.get(j).getMbscode().substring(2,4))) {
					pnum1++;
				}else if (productArr[1][0].equals(baiList.get(j).getMbscode().substring(2,4))) {
					pnum2++;
				}else if (productArr[2][0].equals(baiList.get(j).getMbscode().substring(2,4))) {
					pnum3++;
				}else if (productArr[3][0].equals(baiList.get(j).getMbscode().substring(2,4))) {
					pnum4++;
				}
			}
			reportData.setPnum1(pnum1+"");
			reportData.setPnum2(pnum2+"");
			reportData.setPnum3(pnum3+"");
			reportData.setPnum4(pnum4+"");
			reportData.setPtype1(productArr[0][0]);
			reportData.setPtype2(productArr[1][0]);
			reportData.setPtype3(productArr[2][0]);
			reportData.setPtype4(productArr[3][0]);
			list.add(reportData);
    		//晚班
			reportData2.setBanci("晚班");
    		pnum1 = 0;
    		pnum2 = 0;
    		pnum3 = 0;
    		pnum4 = 0;
    		createCriteria.andMbstimeLike("%"+monthFullDay.get(i)+"%");
    		createCriteria.andMbsremark4EqualTo("晚班");
    		List<MousseBundleSample> wanList = mousseBundleSampleServise.selectByExample(example);
    		for (int j = 0; j < wanList.size(); j++) {
    			if (productArr[0][0].equals(wanList.get(j).getMbscode().substring(2,4))) {
					pnum1++;
				}else if (productArr[1][0].equals(wanList.get(j).getMbscode().substring(2,4))) {
					pnum2++;
				}else if (productArr[2][0].equals(wanList.get(j).getMbscode().substring(2,4))) {
					pnum3++;
				}else if (productArr[3][0].equals(wanList.get(j).getMbscode().substring(2,4))) {
					pnum4++;
				}
			}
    		reportData2.setPnum1(pnum1+"");
			reportData2.setPnum2(pnum2+"");
			reportData2.setPnum3(pnum3+"");
			reportData2.setPnum4(pnum4+"");
			reportData2.setPtype1(productArr[0][0]);
			reportData2.setPtype2(productArr[1][0]);
			reportData2.setPtype3(productArr[2][0]);
			reportData2.setPtype4(productArr[3][0]);
			list.add(reportData2);
			reportData = null;
			reportData2 = null;
    	}
		return list;
    }
    /**
     * 获取离心机产量报表
     * @param format 年月
     * @return 报表
     */
    public List<ReportDataUtils> selectLxjByMonth(String format){
    	List<ReportDataUtils> list = new ArrayList<>();
    	List<String> monthFullDay = getMonthFullDay(format);
    	for (int i = 0; i < monthFullDay.size(); i++) {
    		ReportDataUtils reportData = new ReportDataUtils();
    		ReportDataUtils reportData2 = new ReportDataUtils();
    		
    		CentrifugalExample example = new CentrifugalExample();
    		Criteria createCriteria =  example.createCriteria();
    		//白班
    		reportData.setTime(monthFullDay.get(i));
    		reportData2.setTime(monthFullDay.get(i));
    		reportData.setBanci("白班");
    		int pnum1 = 0;
    		int pnum2 = 0;
    		int pnum3 = 0;
    		int pnum4 = 0;
    		createCriteria.andCtimeLike("%"+monthFullDay.get(i)+"%");
    		createCriteria.andCremark4EqualTo("白班");
    		List<Centrifugal> baiList = centrifugalServise.selectByExample(example);
    		for (int j = 0; j < baiList.size(); j++) {
    			if (baiList.get(j).getCtube().indexOf(productArr[0][3]) != -1) {
    				pnum1++;
    			}else if (baiList.get(j).getCtube().indexOf(productArr[1][3]) != -1) {
    				pnum2++;
    			}else if (baiList.get(j).getCtube().indexOf(productArr[2][3]) != -1) {
    				pnum3++;
    			}else if (baiList.get(j).getCtube().indexOf(productArr[3][3]) != -1) {
    				pnum4++;
    			}
    		}
    		reportData.setPnum1(pnum1+"");
    		reportData.setPnum2(pnum2+"");
    		reportData.setPnum3(pnum3+"");
    		reportData.setPnum4(pnum4+"");
    		reportData.setPtype1(productArr[0][3]);
    		reportData.setPtype2(productArr[1][3]);
    		reportData.setPtype3(productArr[2][3]);
    		reportData.setPtype4(productArr[3][3]);
    		list.add(reportData);
    		//晚班
    		reportData2.setBanci("晚班");
    		pnum1 = 0;
    		pnum2 = 0;
    		pnum3 = 0;
    		pnum4 = 0;
    		createCriteria.andCtimeLike("%"+monthFullDay.get(i)+"%");
    		createCriteria.andCremark4EqualTo("晚班");
    		List<Centrifugal> wanList = centrifugalServise.selectByExample(example);
    		for (int j = 0; j < wanList.size(); j++) {
    			if (wanList.get(j).getCtube().indexOf(productArr[0][3]) != -1) {
    				pnum1++;
    			}else if (wanList.get(j).getCtube().indexOf(productArr[1][3]) != -1) {
    				pnum2++;
    			}else if (wanList.get(j).getCtube().indexOf(productArr[2][3]) != -1) {
    				pnum3++;
    			}else if (wanList.get(j).getCtube().indexOf(productArr[3][3]) != -1) {
    				pnum4++;
    			}
    		}
    		reportData2.setPnum1(pnum1+"");
    		reportData2.setPnum2(pnum2+"");
    		reportData2.setPnum3(pnum3+"");
    		reportData2.setPnum4(pnum4+"");
    		reportData2.setPtype1(productArr[0][3]);
    		reportData2.setPtype2(productArr[1][3]);
    		reportData2.setPtype3(productArr[2][3]);
    		reportData2.setPtype4(productArr[3][3]);
    		list.add(reportData2);
    		reportData = null;
    		reportData2 = null;
    	}
    	return list;
    }
    
    /**
     * 获取切割机产量报表
     * @param format 年月
     * @return 报表
     */
    public List<ReportDataUtils> selectQgjByMonth(String format){
    	List<ReportDataUtils> list = new ArrayList<>();
    	List<String> monthFullDay = getMonthFullDay(format);
    	for (int i = 0; i < monthFullDay.size(); i++) {
    		ReportDataUtils reportData = new ReportDataUtils();
    		ReportDataUtils reportData2 = new ReportDataUtils();
    		
    		CutExample example = new CutExample();
    		com.sdry.model.jyy.CutExample.Criteria createCriteria = example.createCriteria();
    		//白班
    		reportData.setTime(monthFullDay.get(i));
    		reportData2.setTime(monthFullDay.get(i));
    		reportData.setBanci("白班");
    		int pnum1 = 0;
    		int pnum2 = 0;
    		int pnum3 = 0;
    		int pnum4 = 0;
    		createCriteria.andCtimeLike("%"+monthFullDay.get(i)+"%");
    		createCriteria.andCremark9EqualTo("白班");
    		List<Cut> baiList = cutServise.selectByExample(example );
    		for (int j = 0; j < baiList.size(); j++) {
    			if (baiList.get(j).getCtube().indexOf(productArr[0][3]) != -1) {
    				pnum1++;
    			}else if (baiList.get(j).getCtube().indexOf(productArr[1][3]) != -1) {
    				pnum2++;
    			}else if (baiList.get(j).getCtube().indexOf(productArr[2][3]) != -1) {
    				pnum3++;
    			}else if (baiList.get(j).getCtube().indexOf(productArr[3][3]) != -1) {
    				pnum4++;
    			}
    		}
    		reportData.setPnum1(pnum1+"");
    		reportData.setPnum2(pnum2+"");
    		reportData.setPnum3(pnum3+"");
    		reportData.setPnum4(pnum4+"");
    		reportData.setPtype1(productArr[0][3]);
    		reportData.setPtype2(productArr[1][3]);
    		reportData.setPtype3(productArr[2][3]);
    		reportData.setPtype4(productArr[3][3]);
    		list.add(reportData);
    		//晚班
    		reportData2.setBanci("晚班");
    		pnum1 = 0;
    		pnum2 = 0;
    		pnum3 = 0;
    		pnum4 = 0;
    		createCriteria.andCtimeLike("%"+monthFullDay.get(i)+"%");
    		createCriteria.andCremark9EqualTo("晚班");
    		List<Cut> wanList = cutServise.selectByExample(example );
    		for (int j = 0; j < wanList.size(); j++) {
    			if (wanList.get(j).getCtube().indexOf(productArr[0][3]) != -1) {
    				pnum1++;
    			}else if (wanList.get(j).getCtube().indexOf(productArr[1][3]) != -1) {
    				pnum2++;
    			}else if (wanList.get(j).getCtube().indexOf(productArr[2][3]) != -1) {
    				pnum3++;
    			}else if (wanList.get(j).getCtube().indexOf(productArr[3][3]) != -1) {
    				pnum4++;
    			}
    		}
    		reportData2.setPnum1(pnum1+"");
    		reportData2.setPnum2(pnum2+"");
    		reportData2.setPnum3(pnum3+"");
    		reportData2.setPnum4(pnum4+"");
    		reportData2.setPtype1(productArr[0][3]);
    		reportData2.setPtype2(productArr[1][3]);
    		reportData2.setPtype3(productArr[2][3]);
    		reportData2.setPtype4(productArr[3][3]);
    		list.add(reportData2);
    		reportData = null;
    		reportData2 = null;
    	}
    	return list;
    }
   
    /**
     * 获取固化产量报表
     * @param format 年月
     * @return 报表
     */
    public List<ReportDataUtils> selectghByMonth(String format){
    	List<ReportDataUtils> list = new ArrayList<>();
    	List<String> monthFullDay = getMonthFullDay(format);
    	for (int i = 0; i < monthFullDay.size(); i++) {
    		ReportDataUtils reportData = new ReportDataUtils();
    		ReportDataUtils reportData2 = new ReportDataUtils();
    		
    		SolidExample example = new SolidExample();
			com.sdry.model.jyy.SolidExample.Criteria createCriteria = example.createCriteria();
    		//白班
    		reportData.setTime(monthFullDay.get(i));
    		reportData2.setTime(monthFullDay.get(i));
    		reportData.setBanci("白班");
    		int pnum1 = 0;
    		int pnum2 = 0;
    		int pnum3 = 0;
    		int pnum4 = 0;
    		createCriteria.andStarttimeLike("%"+monthFullDay.get(i)+"%");
    		createCriteria.andCremark9EqualTo("白班");
    		List<Solid> baiList = solidServise.selectByExample(example );
    		for (int j = 0; j < baiList.size(); j++) {
    			if (baiList.get(j).getStube().indexOf(productArr[0][3]) != -1) {
    				pnum1++;
    			}else if (baiList.get(j).getStube().indexOf(productArr[1][3]) != -1) {
    				pnum2++;
    			}else if (baiList.get(j).getStube().indexOf(productArr[2][3]) != -1) {
    				pnum3++;
    			}else if (baiList.get(j).getStube().indexOf(productArr[3][3]) != -1) {
    				pnum4++;
    			}
    		}
    		reportData.setPnum1(pnum1+"");
    		reportData.setPnum2(pnum2+"");
    		reportData.setPnum3(pnum3+"");
    		reportData.setPnum4(pnum4+"");
    		reportData.setPtype1(productArr[0][3]);
    		reportData.setPtype2(productArr[1][3]);
    		reportData.setPtype3(productArr[2][3]);
    		reportData.setPtype4(productArr[3][3]);
    		list.add(reportData);
    		//晚班
    		reportData2.setBanci("晚班");
    		pnum1 = 0;
    		pnum2 = 0;
    		pnum3 = 0;
    		pnum4 = 0;
    		createCriteria.andStarttimeLike("%"+monthFullDay.get(i)+"%");
    		createCriteria.andCremark9EqualTo("晚班");
    		List<Solid> wanList = solidServise.selectByExample(example );
    		for (int j = 0; j < wanList.size(); j++) {
    			if (wanList.get(j).getStube().indexOf(productArr[0][3]) != -1) {
    				pnum1++;
    			}else if (wanList.get(j).getStube().indexOf(productArr[1][3]) != -1) {
    				pnum2++;
    			}else if (wanList.get(j).getStube().indexOf(productArr[2][3]) != -1) {
    				pnum3++;
    			}else if (wanList.get(j).getStube().indexOf(productArr[3][3]) != -1) {
    				pnum4++;
    			}
    		}
    		reportData2.setPnum1(pnum1+"");
    		reportData2.setPnum2(pnum2+"");
    		reportData2.setPnum3(pnum3+"");
    		reportData2.setPnum4(pnum4+"");
    		reportData2.setPtype1(productArr[0][3]);
    		reportData2.setPtype2(productArr[1][3]);
    		reportData2.setPtype3(productArr[2][3]);
    		reportData2.setPtype4(productArr[3][3]);
    		list.add(reportData2);
    		reportData = null;
    		reportData2 = null;
    	}
    	return list;
    }
    
    /**
     * 根据年月获取该月的所有日期
     * @param format
     * @return
     * @throws ParseException
     */
    public List<String> getMonthFullDay(String format){
		int year = Integer.valueOf(format.substring(0, 4)); // 年份  
		int month = Integer.valueOf(format.substring(5, 7)); // 月份  
		List<String> monthDays = DateCalculationUtil.getMonthFullDayByYearAndMonth(year, month);
		return monthDays;
    }
    
    

	
	
	
	
	
	/**
	 * 产量物料明细表跳转页面
	 * @return
	 */
	@RequestMapping("/outputMaterielListReport")
	public String materielListReport() {
		return "/report/outputMaterielList";
	}
	 /**
     * 根据当前年月查询产量物料明细表
     * @param response 响应
     * @param format 年月
     * @throws Exception 异常
     */
    @RequestMapping("/selectoutputMaterielListReportByMonth")
    public void selectoutputMaterielListReportByMonth(HttpServletResponse response,
							    		String format) throws Exception {
    	List<OutputMaterielReportDataUtils> list = new ArrayList<>();
    	/*Date da = new Date();
		SimpleDateFormat msdf = new SimpleDateFormat("yyyy-MM");
		String m = msdf.format(da);
		//当前月之前的
    	if(bjYearMonth(format, m)){
    		OutputMaterielReportDataUtils param = new OutputMaterielReportDataUtils();
    		param.setDate(format);
    		list = outputMaterielReportDataUtilsService.queryAllByMution(param);
    	}else{
    		if (m.equals(format)) {
    			list = chaOutputMaterielListReportByMonth(format);
			}
    	}*/
    	if(null == format || "".equals(format)){
			Date da = new Date();
			SimpleDateFormat msdf = new SimpleDateFormat("yyyy-MM");
			format = msdf.format(da);
		}
    	OutputMaterielReportDataUtils param = new OutputMaterielReportDataUtils();
		param.setDate(format);
		list = outputMaterielReportDataUtilsService.queryAllByMution(param);
       
		JSONObject jsonObject=new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("total", list.size());
        jsonObject.put("rows", list);
        ResponseUtil.write(response, jsonObject);
    }
    
    
    
    /**
     * 添加物料信息
     * @param monthFullDay 该月的日期
     * @return
     * @throws Exception
     */
    public List<OutputMaterielReportDataUtils> reportSetMaterielList(List<String> monthFullDay) throws Exception {
    	List<OutputMaterielReportDataUtils> list = new ArrayList<>();

    	Product product = new Product();
		List<Product> products = productService.listAllProduct(product);
		for (int i = 0; i < products.size(); i++) {
			Product product1 = new Product();
			product1.setPid(products.get(i).getPid());
			List<Part> parts = reportServise.listAllPartByProduct(product1);
			for (int j = 0; j < parts.size(); j++) {
				Object obj1 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
				Object obj2 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
				Object obj3 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  

				for (int k = 0; k < monthFullDay.size(); k++) {
					LineSideLibraryOut libraryOut = new LineSideLibraryOut();
					SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
					libraryOut.setOutDate(sdf.parse(monthFullDay.get(k)));
					libraryOut.setPaID(parts.get(j).getPaid());
					libraryOut.setReserve2(products.get(i).getPnum());
					List<LineSideLibraryOut> lineSideLibraryOuts = reportServise.listLineSideLibraryOutByMution(libraryOut);
					String outQuantity = "0";
					for (int k1 = 0; k1 < lineSideLibraryOuts.size(); k1++) {
						outQuantity = StringUtil.calcFloatValue(outQuantity, lineSideLibraryOuts.get(k1).getOutQuantity(), "add");
					}
					//reportData1.setA1(parts.get(j).getParemark3());
					int planNum = selectPlanNum(monthFullDay.get(k), products.get(i).getPnum());
					String num = StringUtil.calcFloatValue(parts.get(j).getParemark3(), String.valueOf(planNum), "multiply");
					BeanReflexUtil.setProperty(obj1,"a"+(k+1), num+"");  
					//reportData2.setA1(outQuantity.toString());
					BeanReflexUtil.setProperty(obj2,"a"+(k+1), outQuantity.toString()); 
					//Float paremark3 = Float.valueOf(parts.get(j).getParemark3());
					//（计划量-实际量）/计划量
					

					String pcl = "0";
					if(Float.parseFloat(num) > Float.parseFloat(pcl)){
						pcl = StringUtil.calcFloatValue(StringUtil.calcFloatValue(num, outQuantity, "subtract"), num, "divide");
					}else{
						if(Float.parseFloat(outQuantity) > Float.parseFloat(pcl)){
							pcl = "1";
						}else{
							pcl = "0";
						}
					}
					//System.out.println(num+"-"+outQuantity+"="+pcl);
					String pcls = Integer.parseInt(new DecimalFormat("0").format(Float.parseFloat(pcl)*100))+"%";
					//reportData3.setA1(pcl.toString());
			    	BeanReflexUtil.setProperty(obj3,"a"+(k+1), pcls);  
				}
				OutputMaterielReportDataUtils reportData1 = (OutputMaterielReportDataUtils) obj1;
				OutputMaterielReportDataUtils reportData2 = (OutputMaterielReportDataUtils) obj2;
				OutputMaterielReportDataUtils reportData3 = (OutputMaterielReportDataUtils) obj3;
				
				reportData1.setT4("BOM量");
				reportData1.setT1(parts.get(j).getParemark4());
				reportData1.setT2(products.get(i).getPnum().substring(5, 9));
				reportData1.setT3(parts.get(j).getPaname());
				reportData2.setT4("实际量");
				reportData2.setT1(parts.get(j).getParemark4());
				reportData2.setT2(products.get(i).getPnum().substring(5, 9));
				reportData2.setT3(parts.get(j).getPaname());
				reportData3.setT4("偏差率");
				reportData3.setT1(parts.get(j).getParemark4());
				reportData3.setT2(products.get(i).getPnum().substring(5, 9));
				reportData3.setT3(parts.get(j).getPaname());
				
				list.add(reportData1);
				list.add(reportData2);
				list.add(reportData3);
			}
		}
		return list;
    }
    /**
     * 添加日产量/排产单
     * @param monthFullDay 该月的日期
     * @return
     * @throws Exception
     */
    public List<OutputMaterielReportDataUtils> reportSetProduct(List<String> monthFullDay) throws Exception {
    	List<OutputMaterielReportDataUtils> list = new ArrayList<>();
    	Object obj1 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
    	Object obj11 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
    	Object obj2 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
    	Object obj21 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
    	Object obj3 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
    	Object obj31 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
    	Object obj4 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
    	Object obj41 = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
		for (int i = 0; i < monthFullDay.size(); i++) {
			int pnum1 = 0;
			int pnum2 = 0;
			int pnum3 = 0;
			int pnum4 = 0;
			String cplan = "";
			CutExample example = new CutExample();
			com.sdry.model.jyy.CutExample.Criteria createCriteria = example.createCriteria();
			createCriteria.andCtimeLike("%"+monthFullDay.get(i)+"%");
			List<Cut> cutList = cutServise.selectByExample(example );
			if (cutList.size()>0) {
				cplan = cutList.get(0).getCplan();
			}
			for (int j = 0; j < cutList.size(); j++) {
				if (cutList.get(j).getCtube().indexOf(productArr[0][3]) != -1) {
    				pnum1++;
    			}else if (cutList.get(j).getCtube().indexOf(productArr[1][3]) != -1) {
    				pnum2++;
    			}else if (cutList.get(j).getCtube().indexOf(productArr[2][3]) != -1) {
    				pnum3++;
    			}else if (cutList.get(j).getCtube().indexOf(productArr[3][3]) != -1) {
    				pnum4++;
    			}
			}
			BeanReflexUtil.setProperty(obj1,"a"+(i+1), pnum1+"");  
			BeanReflexUtil.setProperty(obj11,"a"+(i+1), cplan+"");  
			BeanReflexUtil.setProperty(obj2,"a"+(i+1), pnum2+"");  
			BeanReflexUtil.setProperty(obj21,"a"+(i+1), cplan+"");  
			BeanReflexUtil.setProperty(obj3,"a"+(i+1), pnum3+"");  
			BeanReflexUtil.setProperty(obj31,"a"+(i+1), cplan+"");  
			BeanReflexUtil.setProperty(obj4,"a"+(i+1), pnum4+"");  
			BeanReflexUtil.setProperty(obj41,"a"+(i+1), cplan+"");  
		}
		OutputMaterielReportDataUtils reportData1 = (OutputMaterielReportDataUtils) obj1;
		OutputMaterielReportDataUtils reportData11 = (OutputMaterielReportDataUtils) obj11;
		OutputMaterielReportDataUtils reportData2 = (OutputMaterielReportDataUtils) obj2;
		OutputMaterielReportDataUtils reportData21 = (OutputMaterielReportDataUtils) obj21;
		OutputMaterielReportDataUtils reportData3 = (OutputMaterielReportDataUtils) obj3;
		OutputMaterielReportDataUtils reportData31 = (OutputMaterielReportDataUtils) obj31;
		OutputMaterielReportDataUtils reportData4 = (OutputMaterielReportDataUtils) obj4;
		OutputMaterielReportDataUtils reportData41 = (OutputMaterielReportDataUtils) obj41;
		//白班
		reportData1.setT2("日产量/排产单");
		reportData11.setT2("日产量/排产单");
		reportData2.setT2("日产量/排产单");
		reportData21.setT2("日产量/排产单");
		reportData3.setT2("日产量/排产单");
		reportData31.setT2("日产量/排产单");
		reportData4.setT2("日产量/排产单");
		reportData41.setT2("日产量/排产单");
		
		reportData1.setT3(productArr[0][3]);
		reportData11.setT3(productArr[0][3]);
		reportData2.setT3(productArr[1][3]);
		reportData21.setT3(productArr[1][3]);
		reportData3.setT3(productArr[2][3]);
		reportData31.setT3(productArr[2][3]);
		reportData4.setT3(productArr[3][3]);
		reportData41.setT3(productArr[3][3]);
		
		reportData1.setT4("产量");
		reportData11.setT4("排产单号");
		reportData2.setT4("产量");
		reportData21.setT4("排产单号");
		reportData3.setT4("产量");
		reportData31.setT4("排产单号");
		reportData4.setT4("产量");
		reportData41.setT4("排产单号");
		list.add(reportData1);
		list.add(reportData11);
		list.add(reportData2);
		list.add(reportData21);
		list.add(reportData3);
		list.add(reportData31);
		list.add(reportData4);
		list.add(reportData41);
		return list;
    }
    /**
     * 添加该月每天的星期
     * @param monthFullDay 该月的日期
     * @return
     * @throws Exception
     */
    public OutputMaterielReportDataUtils reportSetWeek(List<String> monthFullDay) throws Exception {
    	Object obj = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
    	for (int i = 0; i < monthFullDay.size(); i++) {
    		BeanReflexUtil.setProperty(obj,"a"+(i+1), DateCalculationUtil.dateToWeek(monthFullDay.get(i)));  
    	}
    	OutputMaterielReportDataUtils reportData = (OutputMaterielReportDataUtils) obj;
    	reportData.setT4("星期");
    	return reportData;
    }
    
	
	public List<OutputMaterielReportDataUtils> reportSetStaff(List<String> monthFullDay) throws Exception {
		List<OutputMaterielReportDataUtils> list = new ArrayList<>();
		//出勤人数
		Team team = new Team();
		List<Team> teams = othersService.teamByMution(team);
		for (int j = 0; j < teams.size(); j++) {
			Object obj = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
			for (int i = 0; i < monthFullDay.size(); i++) {
				List<Integer> counts = countEmployeeRecords(monthFullDay.get(i), teams.get(j).getTname());
				BeanReflexUtil.setProperty(obj,"a"+(i+1), String.valueOf(counts.get(0)));  
			}
			OutputMaterielReportDataUtils reportData = (OutputMaterielReportDataUtils) obj;
			reportData.setT4(teams.get(j).getTname());
			reportData.setT3("出勤人数");
			list.add(reportData);
		}
		//工时
		Object obj = BeanReflexUtil.getBean("com.sdry.model.report.OutputMaterielReportDataUtils");  
		for (int i = 0; i < monthFullDay.size(); i++) {
				Integer time = countTimeEmployeeRecords(monthFullDay.get(i));
		    	BeanReflexUtil.setProperty(obj,"a"+(i+1), DateCalculationUtil.secondZhuanTime(time));  
		}
		OutputMaterielReportDataUtils reportData = (OutputMaterielReportDataUtils) obj;
		reportData.setT4("出勤工时");
		reportData.setT3("规格");
		reportData.setT2("日产量/排产单");
		list.add(reportData);
		return list; 
	}
	/**
	 * 统计工时
	 * @param time 时间
	 * @return
	 * @throws ParseException 
	 */
	public Integer countTimeEmployeeRecords(String time) throws ParseException{
		TeamRecord teamRecord = new TeamRecord();
		teamRecord.setTtime(time);
		//工时（秒）
		int times = 0;
		List<TeamRecord> teamRecords = reportServise.teamRecordByMution(teamRecord);
		for (int i = 0; i < teamRecords.size(); i++) {
			EmployeeRecord employeeRecord = new  EmployeeRecord();
			employeeRecord.setTid(teamRecords.get(i).getTid());
			List<EmployeeRecord> employeeRecords = reportServise.employeeRecordByMution(employeeRecord);
			for (int j = 0; j < employeeRecords.size(); j++) {
				if("".equals(employeeRecords.get(j).getLogoutTime()) || null == employeeRecords.get(j).getLogoutTime()){
					/*SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					SimpleDateFormat sdf1= new SimpleDateFormat("yyyy-MM-dd");
					if(team == "白班"){
						boolean effectiveDate = DateCalculationUtil.isEffectiveDate(employeeRecords.get(j).getLoginTime(), baiBanStart(sdf1.format(new  Date())), baiBanEnd(sdf1.format(new  Date())));
						if(effectiveDate){
							String timeSecondDifference = DateCalculationUtil.getTimeSecondDifference(sdf.format(new  Date()), employeeRecords.get(j).getLoginTime());
							times = times+Integer.valueOf(timeSecondDifference);						}
					}else if(team == "晚班"){
						boolean effectiveDate = DateCalculationUtil.isEffectiveDate(employeeRecords.get(j).getLoginTime(), wanBanStart(sdf1.format(new  Date())), wanBanEnd(sdf1.format(new  Date())));
						if(effectiveDate){
							String timeSecondDifference = DateCalculationUtil.getTimeSecondDifference(sdf.format(new  Date()), employeeRecords.get(j).getLoginTime());
							times = times+Integer.valueOf(timeSecondDifference);
						}
					}*/
				}else{
					String timeSecondDifference = DateCalculationUtil.getTimeSecondDifference(employeeRecords.get(j).getLogoutTime(), employeeRecords.get(j).getLoginTime());
					times = times+Integer.valueOf(timeSecondDifference);
				}
			}
		}
		return times;
	}
	/**
	 * 统计出勤人数+工时
	 * @param time 时间
	 * @param team 班组名称
	 * @return
	 * @throws ParseException 
	 */
	public List<Integer> countEmployeeRecords(String time, String team) throws ParseException{
		List<Integer> list = new ArrayList<>();
		TeamRecord teamRecord = new TeamRecord();
 		teamRecord.setTname(team);
		teamRecord.setTtime(time);
		int num = 0;
		//工时（秒）
		int times = 0;
		List<Long> ulist = new ArrayList<>();
		List<TeamRecord> teamRecords = reportServise.teamRecordByMution(teamRecord);
		for (int i = 0; i < teamRecords.size(); i++) {
			EmployeeRecord employeeRecord = new  EmployeeRecord();
			employeeRecord.setTid(teamRecords.get(i).getTid());
			List<EmployeeRecord> employeeRecords = reportServise.employeeRecordByMution(employeeRecord);
			for (int j = 0; j < employeeRecords.size(); j++) {
				if("".equals(employeeRecords.get(j).getLogoutTime()) || null == employeeRecords.get(j).getLogoutTime()){
					/*SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					SimpleDateFormat sdf1= new SimpleDateFormat("yyyy-MM-dd");
					if(team == "白班"){
						boolean effectiveDate = DateCalculationUtil.isEffectiveDate(employeeRecords.get(j).getLoginTime(), baiBanStart(sdf1.format(new  Date())), baiBanEnd(sdf1.format(new  Date())));
						if(effectiveDate){
							String timeSecondDifference = DateCalculationUtil.getTimeSecondDifference(sdf.format(new  Date()), employeeRecords.get(j).getLoginTime());
							times = times+Integer.valueOf(timeSecondDifference);						}
					}else if(team == "晚班"){
						boolean effectiveDate = DateCalculationUtil.isEffectiveDate(employeeRecords.get(j).getLoginTime(), wanBanStart(sdf1.format(new  Date())), wanBanEnd(sdf1.format(new  Date())));
						if(effectiveDate){
							String timeSecondDifference = DateCalculationUtil.getTimeSecondDifference(sdf.format(new  Date()), employeeRecords.get(j).getLoginTime());
							times = times+Integer.valueOf(timeSecondDifference);
						}
					}*/
				}else{
					String timeSecondDifference = DateCalculationUtil.getTimeSecondDifference(employeeRecords.get(j).getLogoutTime(), employeeRecords.get(j).getLoginTime());
					times = times+Integer.valueOf(timeSecondDifference);
				}
				//如果不包含,人数统计+1
				if (!ulist.contains(employeeRecords.get(j).getUid())) {
					num ++;
					ulist.add(employeeRecords.get(j).getUid());
				}
			}
		}
		list.add(num);
		list.add(times);
		return list;
	}
	

	/**
	 * 根据当前年月查询产量物料明细表
	 * @param format 日期
	 * @return 产量物料明细表
	 * @throws Exception 
	 */
	public List<OutputMaterielReportDataUtils> chaOutputMaterielListReportByMonth(String format) throws Exception{
		List<OutputMaterielReportDataUtils> list = new ArrayList<>();
    	if (format != null && !"".equals(format)) {
    		List<String> monthFullDay = getMonthFullDay(format);
    		list.add(reportSetWeek(monthFullDay));
    		list.addAll(reportSetStaff(monthFullDay));
    		list.addAll(reportSetProduct(monthFullDay));
    		list.addAll(reportSetMaterielList(monthFullDay));
		}
		return list;
	}
    /**
     * 根据当前日期查询设备产量报表
     * @param format 日期
     * @param deviceName 设备名称
     * @return 设备产量报表
     */
    public List<ReportDataUtils> chaDeviceReportByMonth(String format,String deviceName){
    	//纯SQL查询
    	ReportDataUtils record =  new ReportDataUtils();
    	record .setDeviceName(deviceName);
    	record .setDate(format);
		if("膜丝".equals(deviceName)){
			record.setPtype1(productArr[0][0]);
			record.setPtype2(productArr[1][0]);
			record.setPtype3(productArr[2][0]);
			record.setPtype4(productArr[3][0]);
    	}else{
    		record.setPtype1(productArr[0][3]);
			record.setPtype2(productArr[1][3]);
			record.setPtype3(productArr[2][3]);
			record.setPtype4(productArr[3][3]);
    	}
		//java查询
		/*List<ReportDataUtils> list = new ArrayList<>();
    	if("离心".equals(deviceName)){
    		list = selectLxjByMonth(format);
    	}else if("切割".equals(deviceName)){
    		list = selectQgjByMonth(format);
    	}else if("膜丝".equals(deviceName)){
    		list = selectMsByMonth(format);
    	}else if("组装".equals(deviceName)){
    		list = selectZzByMonth(format);
    	}else if("固化".equals(deviceName)){
    		list = selectghByMonth(format);
    	}*/
    	List<ReportDataUtils> list = reportDataUtilsService.chaReportDataUtilsByDeviceNameAndDateAndType(record);
    	return list;
    }
    public int addDeviceReportPl(String format,String deviceName){
    	int num = 0;
    	List<ReportDataUtils> list = chaDeviceReportByMonth(format, deviceName);
		for (int i = 0; i < list.size(); i++) {
			reportDataUtilsService.insert(list.get(i));
			num++;
		}
		return num;
    }
    //@Scheduled(cron="0 0 08 * * ?")   //每天9点执行一次       
    public void execute() throws Exception{     
		Date da = new Date();
		SimpleDateFormat msdf = new SimpleDateFormat("yyyy-MM");
		SimpleDateFormat dsdf = new SimpleDateFormat("yyyy-MM-dd");
		String m = msdf.format(da);
		String day = dsdf.format(da);
		if(day.equals(m+"-01")){
			m = getLastMonth(m);
		}
		System.out.println(m+"    "+day);
		//设备产量报表删除
		reportDataUtilsService.deleteByDate(m);
		//设备产量报表添加
		addDeviceReportPl(m, "离心");
		addDeviceReportPl(m, "切割");
		addDeviceReportPl(m, "膜丝");
		addDeviceReportPl(m, "组装");
		addDeviceReportPl(m, "固化");
		//查询产量物料明细表报表信息
		List<OutputMaterielReportDataUtils> outputMaterielList = chaOutputMaterielListReportByMonth(m);
		//产量物料明细表删除
		outputMaterielReportDataUtilsService.deleteByDate(m);
		for (int i = 0; i < outputMaterielList.size(); i++) {
			OutputMaterielReportDataUtils outputMaterielReport = outputMaterielList.get(i);
			outputMaterielReport.setDate(m);
			outputMaterielReportDataUtilsService.insert(outputMaterielReport);
		}
    } 
    /** 获得上月:yyyy-MM
     * @throws ParseException */
	public static String getLastMonth(String date) throws ParseException {
		Calendar c = Calendar.getInstance();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM"); 
		c.setTime(sdf.parse(date));
		c.add(Calendar.MONTH, -1);
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59);
		SimpleDateFormat startSdf = new SimpleDateFormat("yyyy-MM");
		return startSdf.format(c.getTime());
	}
	
	/**
	 * 比较两个月份大小
	 * @param date1 月份1
	 * @param date2 月份2
	 * @return date1 < date2 true  例如：bjYearMonth("2019-01", "2019-02") true
	 * @throws ParseException
	 */
	public static Boolean bjYearMonth(String date1,String date2) throws ParseException{
		Boolean flg = true;
		int d1 = getYearMonth(date1);
		int d2 = getYearMonth(date2);
		if(d1<d2){//d1比d2晚
			flg = true;
		}else{//d1比d2早
			flg = false;
		}
		return flg;
	}
	public static int getYearMonth(String date) throws ParseException{//传入日期
	     Calendar cal = Calendar.getInstance();
	     SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM"); 
	     cal.setTime(sdf.parse(date));
	     int year = cal.get(Calendar.YEAR);//获取年份
	     int month=cal.get(Calendar.MONTH);//获取月份
	     return year*100+month;//返回年份乘以100加上月份的值，因为月份最多2位数，所以年份乘以100可以获取一个唯一的年月数值
	}
	@RequestMapping("/gengxinbaobiaoD")
	public void gengxinbaobiaoD(HttpServletResponse response,String m) throws Exception{
		if(null == m || "".equals(m)){
			Date da = new Date();
			SimpleDateFormat msdf = new SimpleDateFormat("yyyy-MM");
			m = msdf.format(da);
		}
		int flg = 0;
		//设备产量报表删除
		reportDataUtilsService.deleteByDate(m);
		//设备产量报表添加
		flg += addDeviceReportPl(m, "离心");
		flg += addDeviceReportPl(m, "切割");
		flg += addDeviceReportPl(m, "膜丝");
		flg += addDeviceReportPl(m, "组装");
		flg += addDeviceReportPl(m, "固化");
		ResponseUtil.write(response,flg);
	}
	@RequestMapping("/gengxinbaobiaoM")
	public void gengxinbaobiaoM(HttpServletResponse response,String m) throws Exception{
		if(null == m || "".equals(m)){
			Date da = new Date();
			SimpleDateFormat msdf = new SimpleDateFormat("yyyy-MM");
			m = msdf.format(da);
		}
		int flg = 0;
		//查询产量物料明细表报表信息
		List<OutputMaterielReportDataUtils> outputMaterielList = chaOutputMaterielListReportByMonth(m);
		//产量物料明细表删除
		outputMaterielReportDataUtilsService.deleteByDate(m);
		for (int i = 0; i < outputMaterielList.size(); i++) {
			OutputMaterielReportDataUtils outputMaterielReport = outputMaterielList.get(i);
			outputMaterielReport.setDate(m);
			outputMaterielReportDataUtilsService.insert(outputMaterielReport);
			flg ++; 
		}
		ResponseUtil.write(response,flg);
	}
	@Resource
	private ShedudetailServise shedudetailServise;
	/**
	 * 根据日期和产品编号查询对应的计划量
	 * @param format
	 * @param product
	 * @return
	 */
	public int selectPlanNum(String format,String product){
		String num = "";
		ShedudetailExample example = new ShedudetailExample();
		com.sdry.model.jyy.ShedudetailExample.Criteria createCriteria = example.createCriteria();
		createCriteria.andRemark1EqualTo(format);
		//根据时间查询排产单
		List<Shedudetail> list = shedudetailServise.selectByExample(example );
		if(list.size() >0) {
			if("PSH2-0960-T-01".equals(product)) {
				//b1
				num = list.get(0).getB1();
			}else if("PSH2-0980-T-02".equals(product)) {
				//c1
				num = list.get(0).getC1();
			}else if("PSH1-1080-C-04".equals(product)) {
				//d1
				num = list.get(0).getD1();
			}else if("PSH1-1060-B-03".equals(product)) {
				//e1
				num = list.get(0).getE1();
			}else if("".equals(product) || null == product) {
				int count = StringUtil.strNum(list.get(0).getB1())
						+StringUtil.strNum(list.get(0).getC1())
						+StringUtil.strNum(list.get(0).getD1())
						+StringUtil.strNum(list.get(0).getE1());
				num = String.valueOf(count);
			}
		}
		return StringUtil.strNum(num);
	}
}
